#include <iostream>
#include <vector>
#include <set>
#include <fstream>
#include <string>

using namespace std;

static pair<bool, int> sudoku_solver(vector<vector<int>> vv) {
    int x = -1;
    int y = -1;
    for (int i = 0; i < vv.size(); ++i) {
        for (int j = 0; j < vv.size(); ++j) {
            if (vv[i][j] == 0) {
                x = i;
                y = j;
                break;
            }
        }
    }
    if (x == -1)
        return {true, 100 * vv[0][0] + 10 * vv[0][1] + vv[0][2]};

    set<int> s {1, 2, 3, 4, 5, 6, 7, 8, 9};
    for (int i = 0; i < 9; ++i) {
        if (vv[i][y] != 0)
            s.erase(vv[i][y]);
        if (vv[x][i] != 0)
            s.erase(vv[x][i]);
    }
    const vector<vector<int>> dir {
        {-1, -1}, {-1, 0}, {-1, 1},
        {0, -1}, {0, 0}, {0, 1},
        {1, -1}, {1, 0}, {1, 1},
    };
    int x0 = x < 3 ? 1 : (x < 6 ? 4 : 7);
    int y0 = y < 3 ? 1 : (y < 6 ? 4 : 7);
    for (auto p : dir) {
        int xx = x0 + p[0];
        int yy = y0 + p[1];
        if (vv[xx][yy] != 0)
            s.erase(vv[xx][yy]);
    }

    for (int i : s) {
        vv[x][y] = i;
        auto tmp = sudoku_solver(vv);
        if (tmp.first) 
            return {true, tmp.second};
    }

    return {false, 0};
}

static bool sudoku_solver(vector<vector<int>>& vv, int start = 0) {
    int x0 = -1;
    int y0 = -1;
    for (int k = start; k < 81; ++k) {
        int i = k / 9;
        int j = k % 9;
        if (vv[i][j] == 0) {
            x0 = i;
            y0 = j;
            break;
        }
    }
    if (x0 == -1)
        return true;

    set<int> s {1, 2, 3, 4, 5, 6, 7, 8, 9};
    for (int i = 0; i < 9; ++i) {
        if (vv[i][y0] != 0)
            s.erase(vv[i][y0]);
        if (vv[x0][i] != 0)
            s.erase(vv[x0][i]);
    }
    const vector<vector<int>> dir {
        {-1, -1}, {-1, 0}, {-1, 1},
        {0, -1}, {0, 0}, {0, 1},
        {1, -1}, {1, 0}, {1, 1},
    };
    int xc = x0 < 3 ? 1 : (x0 < 6 ? 4 : 7);
    int yc = y0 < 3 ? 1 : (y0 < 6 ? 4 : 7);
    for (auto p : dir) {
        int xx = xc + p[0];
        int yy = yc + p[1];
        if (vv[xx][yy] != 0)
            s.erase(vv[xx][yy]);
    }

    for (int e : s) {
        vv[x0][y0] = e;
        if (sudoku_solver(vv, 9 * x0 + y0 + 1))
            return true;
    }

    vv[x0][y0] = 0;
    return false;
}

int main() {
    int ans = 0;
    string line;
    ifstream file {"./96.txt"};
    while (getline(file, line)) {
        vector<vector<int>> vv;
        for (int i = 0; i < 9; ++i) {
            getline(file, line);
            vector<int> v;
            for (char c : line) 
                v.push_back(c - '0');
            vv.push_back(v);
        }      
#if 0 
        auto tmp = sudoku_solver(vv);
        ans += tmp.second;
#else // save 2 seconds 
        sudoku_solver(vv, 0);
        ans += vv[0][0] * 100 + vv[0][1] * 10 + vv[0][2];
#endif 
    }
    file.close();
    cout << ans << endl;
}